﻿using Core.Audit;
using Core.Migrations.Extensions;
using FluentMigrator;

namespace Infrastructure.Persistence.Migrations.Audits;

[Migration(202510121411)]
public class CreateColumn : ForwardOnlyMigration
{
    public override void Up()
    {
        Alter.Table(typeof(AuditTrail).GetTableName())
          .InSchema(SchemaNames.Identity)
          .AddColumn("TenantId").AsString(int.MaxValue).Nullable().WithColumnDescription("租户标识")
          .AddColumn(MigrationExpressions.ColumnNameFor<AuditTrail>(nameof(AuditTrail.UserId))).AsGuid().Nullable().WithColumnDescription("用户ID")
          .AddColumn(MigrationExpressions.ColumnNameFor<AuditTrail>(nameof(AuditTrail.Operation))).AsString(32).Nullable().WithColumnDescription("操作类型")
          .AddColumn(MigrationExpressions.ColumnNameFor<AuditTrail>(nameof(AuditTrail.Entity))).AsString(64).Nullable().WithColumnDescription("实体类名称")
          .AddColumn(MigrationExpressions.ColumnNameFor<AuditTrail>(nameof(AuditTrail.DateTime))).AsDateTimeOffset().Nullable().WithColumnDescription("操作时间")
          .AddColumn(MigrationExpressions.ColumnNameFor<AuditTrail>(nameof(AuditTrail.PreviousValues))).AsString(int.MaxValue).Nullable().WithColumnDescription("操作前属性")
          .AddColumn(MigrationExpressions.ColumnNameFor<AuditTrail>(nameof(AuditTrail.NewValues))).AsString(int.MaxValue).Nullable().WithColumnDescription("操作后属性")
          .AddColumn(MigrationExpressions.ColumnNameFor<AuditTrail>(nameof(AuditTrail.ModifiedProperties))).AsString(int.MaxValue).Nullable().WithColumnDescription("修改的属性列")
          .AddColumn(MigrationExpressions.ColumnNameFor<AuditTrail>(nameof(AuditTrail.PrimaryKey))).AsString(64).Nullable().WithColumnDescription("操作数据的主键");
    }
}
